/**
 * 
 */
package com.revenco.bi.dao.nutz;

import java.util.List;

import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.revenco.bi.dao.TnChartBaseinfoDao;
import com.revenco.bi.model.TnChartBaseinfo;
import com.revenco.bi.model.userbean.OilGaugeBean;

/**
 * @author LingJun
 * @version $Revision:1.0.0, 2014年1月21日 下午3:11:19
 */
@Repository
public class TnChartBaseinfoDaoImpl extends AstractDaoImpl implements
		TnChartBaseinfoDao {
	
	@Autowired
	private JdbcTemplate jdbcTemplate = null; 
	
	public List<TnChartBaseinfo> getChartList() {
		return this.getDao().query(TnChartBaseinfo.class, null);
	}

	public List<TnChartBaseinfo> getChartinfoById(String chartId) {
		Condition condition = Cnd.where("chartId", "=", chartId);
		return this.getDao().query(TnChartBaseinfo.class, condition);
	}

	/**
	 * 保存图表基本信息表
	 */
	public void saveChartBaseInfo(TnChartBaseinfo tnBaseinfo) {
		this.getDao().insert(tnBaseinfo);
	}

	/**
	 * 更新图表基本信息表
	 */
	public void updateChartBaseInfo(TnChartBaseinfo tnBaseinfo) {
		Chain c = Chain.from(tnBaseinfo);
		Condition con = Cnd.where("chartId", "=", tnBaseinfo.getChartId());
		this.getDao().update(TnChartBaseinfo.class, c, con);
		// this.getDao().update(tnBaseinfo);
	}

	public boolean deleteById(String chartId) {
		Sql sql = Sqls
				.create("Delete FROM FRNT.TN_CHART_BASEINFO WHERE CHART_ID = @chartId");
		sql.params().set("chartId", chartId);
		this.getDao().execute(sql);
		return true;
	}
	
	/**
	 * sql查询油量表相关信息
	 */
	public OilGaugeBean getOilGaugeBeanInfo(String sql) {
		return this.jdbcTemplate.queryForObject(sql, BeanPropertyRowMapper.newInstance(OilGaugeBean.class));
	}
}
